find_package(PkgConfig)
pkg_check_modules(PC_DIRECTFB directfb)
find_path(DIRECTFB_INCLUDE_DIRS
    NAMES directfb.h
    HINTS ${PC_DIRECTFB_INCLUDEDIR}
    ${PC_DIRECTFB_INCLUDE_DIRS}
    PATH_SUFFIXES directfb
)

find_library(DIRECTFB_LIBRARIES
    NAMES directfb
    HINTS ${PC_DIRECTFB_LIBDIR}
    ${PC_DIRECTFB_LIBRARY_DIRS}
)

find_library(DIRECT_LIBRARIES
    NAMES direct
    HINTS ${PC_DIRECTFB_LIBDIR}
    ${PC_DIRECTFB_LIBRARY_DIRS}
)

find_library(FUSION_LIBRARIES
    NAMES fusion
    HINTS ${PC_DIRECTFB_LIBDIR}
    ${PC_DIRECTFB_LIBRARY_DIRS}
)

list(APPEND DIRECTFB_LIBRARIES ${DIRECT_LIBRARIES})
list(APPEND DIRECTFB_LIBRARIES ${FUSION_LIBRARIES})

message("PC_DIRECTFB_INCLUDEDIR=${PC_DIRECTFB_INCLUDEDIR} PC_DIRECTFB_LIBDIR=${PC_DIRECTFB_LIBDIR}")
message("DIRECTFB_LIBRARIES=${DIRECTFB_LIBRARIES} DIRECTFB_INCLUDE_DIRS=${DIRECTFB_INCLUDE_DIRS} PC_DIRECTFB_VERSION=${PC_DIRECTFB_VERSION}")

if(DIRECTFB_INCLUDE_DIRS AND DIRECTFB_LIBRARIES)
    set(DIRECTFB_FOUND TRUE)
    set(DIRECTFB_LIBRARY ${DIRECTFB_LIBRARIES})
    set(DIRECTFB_INCLUDE_DIR ${DIRECTFB_INCLUDE_DIRS})
    set(DIRECTFB_VERSION ${PC_DIRECTFB_VERSION})
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DirectFB REQUIRED_VARS DIRECTFB_INCLUDE_DIRS DIRECTFB_LIBRARIES 
	FOUND_VAR DIRECTFB_FOUND VERSION_VAR DIRECTFB_VERSION)

mark_as_advanced(DIRECTFB_LIBRARIES DIRECTFB_LIBRARY DIRECTFB_INCLUDE_DIRS DIRECTFB_INCLUDE_DIR DIRECTFB_FOUND)

